<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    body {
      background: darkslateblue;
    }

    #time {
      height: 100px;
      line-height: 100px;
      border: 1px dashed yellow;
      text-align: center;
      color: #fff;
      font-size: 26px;
    }
  </style>
</head>

<body>
  <div id="time"></div>
  <script>
	  var timebox=document.getElementById("time");
      var endtime=new Date("2022-5-7 16:00:00");
	  var timer=null;
	  
	  function  addZero(n){
		  return n<10?"0"+n:n;
	  }
	  
	  function showtime(endtime){
		  //var endtime=new Date(2022,4,3,12,00,00);
		  var nowtime=new Date();
		  var difftime=(endtime-nowtime)/1000;//秒  时间差
		  
		  if(difftime<=0){
			  clearInterval(timer);
			  timer=null;
			  return "活动已经结束"
		  }
		  
		  var hours=parseInt(difftime/3600);
		  var minutes=parseInt((difftime-difftime/3600)/60);
		  var seconds=parseInt(difftime-difftime/3600-minutes*60);
		  var res=addZero(hours)+":"+addZero(minutes)+":"+addZero(seconds);
		  return res;
	  }
	  
	  timebox.innerHTML=showtime(endtime);
	  
	  timer=setInterval(()=>{
		timebox.innerHTML=showtime(endtime);
	  },1000)
	  
  </script>
</body>

</html>